package cn.wolfcode.luowowo.comment.service.impl;

import cn.wolfcode.luowowo.comment.domain.CommunityComment;
import cn.wolfcode.luowowo.comment.domain.StrategyComment;
import cn.wolfcode.luowowo.comment.query.CommunityCommentQuery;
import cn.wolfcode.luowowo.comment.repository.ICommunityCommentRepository;
import cn.wolfcode.luowowo.comment.service.ICommunityCommentService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * Created by admin on 2019/8/13.
 */
@Service
public class CommunityCommentServiceImpl implements ICommunityCommentService {

    @Autowired
    private MongoTemplate template;

    @Autowired
    private ICommunityCommentRepository repository;


    @Override
    public void save(CommunityComment comment) {
        if (!StringUtils.hasLength(comment.getAskId().toString())) {
            comment.setCreateTime(new Date());
        }
        repository.save(comment);
    }

    @Override
    public List<CommunityComment> listById(Long askId, Long id ) {
        Query query = new Query();
        Criteria criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("askId").is(askId),
                Criteria.where("aid").is(id));
        query.addCriteria(criteria);
        List<CommunityComment> list = template.find(query, CommunityComment.class, "community_comment");
        return list;
    }
}
